/************************************************************************/
/*																		*/
/*					Project 1		CONNECT FOUR						*/
/*																		*/
/*						Team 2											*/	
/*																		*/
/*			Fearless Leader: David Buckner								*/
/*			Recorder:		 Phyllisia Gaines							*/
/*			Average Joe:	 Drew White									*/
/*																		*/
/*			This program is a cheap imitation of the popular			*/
/*			Milton Bradley game Connect 4. The object of the			*/
/*			game is to drop pieces until you have 4 consecutive			*/
/*			pieces in a row. The player to do this first wins.			*/
/*																		*/
/************************************************************************/



#include<iostream>

#include"board.h"

#include"player.h"

using namespace std;

/************************************************************************/




void main()
{	
	
	char playAgain='y';

	int pTurn=1;

	int choice=0;

	string pName;

/************************************************************************/


	cout << " Player 1, please enter your name:  ";

	cin >> pName;

	Player Player1(pName, pTurn);

	cout << endl << " Player 2, please enter your name:  ";

	cin >> pName;

	pTurn=2;

	Player Player2(pName, pTurn);

	pTurn=1;

	while(playAgain=='y')
	{

		Board PlayBoard;

		while(pTurn!=3)
		{
			system("cls");

			PlayBoard.DrawBoard();

			cout << " " << Player1.GetName() <<", ";
			
			choice=10;

			do
			{
				if(PlayBoard.ReturnArrValue(0,choice-1)!=' ')

				cout<<"Please enter a column that is not full"<<endl;

				choice=Player1.GetColChoice();

			}while(PlayBoard.ReturnArrValue(0,choice-1)!=' ');


			PlayBoard.DropPiece(Player1.GetTurn(), choice);

			choice=0;

			PlayBoard.DrawBoard();



			if(PlayBoard.CheckForWinner())
			{
				cout << " " << Player1.GetName() << " wins!" << endl;
				break;
			}



			if(PlayBoard.CheckForTie())
			{
				cout << " The game was a tie." << endl;
				break;

			}



			cout << Player2.GetName() << ", ";

			choice=10;
			do
			{
				if(PlayBoard.ReturnArrValue(0,choice-1)!=' ')

					cout<<"Please enter a column that is not full"<<endl;

				choice=Player2.GetColChoice();

			}while(PlayBoard.ReturnArrValue(0,choice-1)!=' ');

			PlayBoard.DropPiece(Player2.GetTurn(), choice);

			PlayBoard.DrawBoard();



			if(PlayBoard.CheckForWinner())
			{
				cout << " " << Player2.GetName() <<" wins!" << endl;
				break;
			}


			
			if(PlayBoard.CheckForTie())
			{
				cout<<" The game was a tie." << endl;
				break;
			}



		}

		cout << endl <<" Play again? (y/n): ";

		cin >> playAgain;

		cout << endl;
	}
	
}